package com.tedu.login.controller;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/v1/")
public class LRController {

    private static final Map<String,String> user = new HashMap<>();
    @PostMapping("login")
    public String login(@RequestBody Map<String, String> payload) {
        String username = payload.get("username");
        String password = payload.get("password");

        if(username != null && password != null && user.containsKey(username) && user.get(username).equals(password)){
            return "loginSuccess";
        }
        return "loginFailed";
    }

    @PostMapping("register")
    public String register(@RequestBody Map<String, String> payload) {
        String username = payload.get("username");
        String password = payload.get("password");
        user.put(username, password);
        return "registerSuccess";
    }

}